home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
Pascal
/
Book Demos in Pascal
/
SpriteEngine
/
SE No Timer
/
SpriteHandlers.p
< prev
next >
Wrap
Text File
|
1995-04-06
|
4KB
|
140 lines
unit SpriteHandlers;
interface
uses
{$IFC UNDEFINED THINK_PASCAL}
Types, QuickDraw, Fonts, Events, Packages, Menus, Dialogs, Windows,{}
OSUtils, ToolUtils, OSEvents,
{$ENDC}
QDOffScreen, SpriteStructure, SpriteTools;
procedure MoveSprite (theSprite: SpritePtr);
procedure HitSprite (theSprite: SpritePtr; anotherSprite: SpritePtr);
procedure InitSprites;
implementation
{ Custom handlers - application dependent ***}
{}
{Edit this as necessary. It should always include the following three routines:}
{}
{MoveSprite: move the sprite}
{}
{HitSprite: handle collisions between two sprites}
{}
{InitSprites: Load all faces and create initial sprites }
var
firstFace, secondFace, thirdFace:GrafPtr;
Procedure MoveSprite(theSprite:SpritePtr);
begin
theSprite^.speed.v := theSprite^.speed.v + 1; { Simple gravity}
theSprite^.fixedPointPosition.h := theSprite^.fixedPointPosition.h + theSprite^.speed.h;
theSprite^.fixedPointPosition.v := theSprite^.fixedPointPosition.v + theSprite^.speed.v;
theSprite^.position.h := BSR(theSprite^.fixedPointPosition.h , 4);
theSprite^.position.v := BSR(theSprite^.fixedPointPosition.v , 4);
if KeepOnScreenFixed(theSprite) then;
End; (*MoveSprite*)
Procedure HitSprite(theSprite:SpritePtr; anotherSprite:SpritePtr);
var tempSpeed:Integer;
begin
If RectSeparate(theSprite, anotherSprite) >= 2 Then { 2 or 3: horizontal, otherwise vertical}
begin
tempSpeed := theSprite^.speed.h;
theSprite^.speed.h := anotherSprite^.speed.h;
anotherSprite^.speed.h := tempSpeed;
theSprite^.fixedPointPosition.h := BSL(theSprite^.position.h , 4);
End
Else
begin
tempSpeed := theSprite^.speed.v;
theSprite^.speed.v := anotherSprite^.speed.v;
anotherSprite^.speed.v := tempSpeed;
theSprite^.fixedPointPosition.v := BSL(theSprite^.position.v , 4);
End;
End; (*HitSprite*)
Procedure InitSprites;
var theSprite:SpritePtr;
(*Load all pictures*)
begin
firstFace := LoadFaceFromCicn(128); (*cicn resource #128.*)
secondFace := LoadFaceFromCicn(129); (*cicn resource #129.*)
thirdFace := LoadFaceFromCicn(130); (*cicn resource #130.*)
(*Create sprites*)
theSprite := NewSprite;
theSprite^.face := firstFace;
SetPt(theSprite^.fixedPointPosition, BSL(100 , 4), BSL(100 , 4));
SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
theSprite := NewSprite;
theSprite^.face := secondFace;
SetPt(theSprite^.fixedPointPosition, BSL(50 , 4), BSL(50 , 4));
SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
theSprite := NewSprite;
theSprite^.face := thirdFace;
SetPt(theSprite^.fixedPointPosition, BSL(150 , 4), BSL(150 , 4));
SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
{ extra}
theSprite := NewSprite;
theSprite^.face := firstFace;
SetPt(theSprite^.fixedPointPosition, BSL(100 , 4), BSL(100 , 4));
SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
theSprite := NewSprite;
theSprite^.face := secondFace;
SetPt(theSprite^.fixedPointPosition, BSL(50 , 4), BSL(50 , 4));
SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
theSprite := NewSprite;
theSprite^.face := thirdFace;
SetPt(theSprite^.fixedPointPosition, BSL(150 , 4), BSL(150 , 4));
SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
theSprite := NewSprite;
theSprite^.face := firstFace;
SetPt(theSprite^.fixedPointPosition, BSL(100 , 4), BSL(100 , 4));
SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
theSprite := NewSprite;
theSprite^.face := secondFace;
SetPt(theSprite^.fixedPointPosition, BSL(50 , 4), BSL(50 , 4));
SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
theSprite := NewSprite;
theSprite^.face := thirdFace;
SetPt(theSprite^.fixedPointPosition, BSL(150 , 4), BSL(150 , 4));
SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
theSprite := NewSprite;
theSprite^.face := firstFace;
SetPt(theSprite^.fixedPointPosition, BSL(100 , 4), BSL(100 , 4));
SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
theSprite := NewSprite;
theSprite^.face := secondFace;
SetPt(theSprite^.fixedPointPosition, BSL(50 , 4), BSL(50 , 4));
SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
theSprite := NewSprite;
theSprite^.face := thirdFace;
SetPt(theSprite^.fixedPointPosition, BSL(150 , 4), BSL(150 , 4));
SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
End; (*InitSprites*)
end.